package com.varian.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.varian.service.annotation.Resubmit;
import com.varian.service.web.BaseController;
import com.varian.system.dto.SysNoticeDTO;
import com.varian.system.dto.SysNoticePageDTO;
import com.varian.system.service.ISysNoticeService;
import com.varian.system.vo.SysNoticeVO;
import com.varian.tool.result.IR;
import com.varian.tool.result.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author ben
 * @since 2024/8/27
 */
@Resubmit
@RestController
@Tag(name = "通知控制层")
@RequestMapping("/notice")
public class SysNoticeController extends BaseController<ISysNoticeService> {

    @Operation(summary = "新增通知")
    @PostMapping
    @PreAuthorize("@eh.isAdmin()")
    public IR add(@Validated @RequestBody SysNoticeDTO dto){
        return R.status(baseService.add(dto));
    }

    @Operation(summary = "通知分页")
    @GetMapping("page")
    @PreAuthorize("@eh.isAdmin()")
    public R<Page<SysNoticeVO>> page(@Validated SysNoticePageDTO dto){
        return R.data(baseService.page(dto));
    }

    @Operation(summary = "通知详情")
    @GetMapping("{id:\\d+}")
    @PreAuthorize("@eh.isAdmin()")
    public R<SysNoticeVO> detail(@PathVariable("id") Long id){
        return R.data(baseService.detail(id));
    }

    @Operation(summary = "发布通知")
    @PutMapping("publish/{id:\\d+}")
    @PreAuthorize("@eh.isAdmin()")
    public IR publish(@PathVariable("id") Long id){
        return R.status(baseService.publish(id));
    }

    @Operation(summary = "撤销通知")
    @PutMapping("revoke/{id:\\d+}")
    @PreAuthorize("@eh.isAdmin()")
    public IR revoke(@PathVariable("id") Long id){
        return R.status(baseService.revoke(id));
    }

    @Operation(summary = "修改通知")
    @PutMapping("{id:\\d+}")
    @PreAuthorize("@eh.isAdmin()")
    public IR modify(@PathVariable("id") Long id, @Validated @RequestBody SysNoticeDTO dto){
        return R.status(baseService.modify(id, dto));
    }

    @Operation(summary = "删除通知")
    @DeleteMapping("{id:\\d+}")
    @PreAuthorize("@eh.isAdmin()")
    public IR delete(@PathVariable("id") Long id){
        return R.status(baseService.delete(id));
    }
}
